<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\relation\BelongsTo;

/**
 * @mixin \think\Model
 */
class AdminLeaveProcessFlow extends Model
{
    const ACTION_APPLY = "apply"; // 申请
    const ACTION_AUDIT = "audit"; // 审批

    const RESULT_APPROVED = "approved"; // 同意
    const RESULT_REFUSED = "refused"; // 驳回

    const STATE_READY = "ready"; // 准备
    const STATE_PROCESS = "process"; // 正在处理
    const STATE_COMPLETE = "complete"; // 处理完成
    const STATE_CANCEL = "cancel"; // 取消

    const STATE_ARR = ['ready'=>'准备','process'=>'正在处理','complete'=>'处理完成','cancel'=>'取消'];
    const RESULT_ARR = ['approved'=>'同意','refused'=>'驳回'];
    const ACTION_ARR = ['apply'=>'申请','audit'=>'审批'];

    //
    protected $autoWriteTimestamp = true;

    public function school() {
        return $this->belongsTo(AdminSchool::class, 'school_id')
            ->where('is_delete', 0)->bind([
                'school_name' => 'name'
            ]);
    }

    public function staff(): BelongsTo {
        return $this->belongsTo(AdminStaff::class, 'staff_id')->bind([
            'staff_name' => 'name',
            'staff_type' => 'type',
            'staff_type_text' => 'type_text',
            'student_no',
            'sex',
        ]);
    }

    public function getAuditTimeAttr($value) {
        return $value ? date('Y-m-d H:i:s', $value) : '';
    }
    public function getStateTextAttr($value,$data)
    {
        $type = self::STATE_ARR;
        return $data['state'] ? $type[$data['state']] : '';
    }
    public function getActionTextAttr($value,$data)
    {
        $type = self::ACTION_ARR;
        return $data['action'] ? $type[$data['action']] : '';
    }
    public function getResultTextAttr($value,$data)
    {
        $type = self::RESULT_ARR;
        return $data['result'] ? $type[$data['result']] : '';
    }


}
